# -*- coding: utf-8 -*- # 
import ColorPanel
import wx
import Const
class BookCover(wx.ListCtrl):
    def __init__(self, parent, id):
        
        wx.ListCtrl.__init__(self, parent, id, style=
                            wx.LC_ICON
                            )


    def loadData(self,bookData):
        pass
    def makeColorPanel(self, color):
        p = wx.Panel(self, -1)
        win = ColorPanel.ColoredPanel(p, color)
        p.win = win
        def OnCPSize(evt, win=win):
            win.SetPosition((0,0))
            win.SetSize(evt.GetSize())
        p.Bind(wx.EVT_SIZE, OnCPSize)
        return p


    def OnPageChanged(self, event):
        old = event.GetOldSelection()
        new = event.GetSelection()
        sel = self.GetSelection()
        #self.log.write('OnPageChanged,  old:%d, new:%d, sel:%d\n' % (old, new, sel))
        print('OnPageChanged,  old:%d, new:%d, sel:%d\n' % (old, new, sel))
        event.Skip()

    def OnPageChanging(self, event):
        old = event.GetOldSelection()
        new = event.GetSelection()
        sel = self.GetSelection()
        #self.log.write('OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel))
        print('OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel))
        event.Skip()

#================================================================
#================================================================

class SearchOptionPnl(wx.Panel):
    """Search Option Panel: 
        All: CheckBox
        Isbn:Radio
        Author:Radio"""
    
    def __init__(self,parent,optionSize = (70,30),locale = Const.CHINESE):
        print self.__doc__
        self.optLable = optLable = Const.getLable("searchOptTitle",locale)
        self.optValue = optValue = Const.getLableValue("searchOptTitle")
        wx.Panel.__init__(self,parent,-1)
        self.defaultSize = size = optionSize
        
        #Any(Check Box) 
        self.chkbAll = wx.CheckBox(self,label = u"任意",size = size)
        
        self.optBtnList = optBtnList = []
        loStyle = wx.RB_GROUP
        for name in optValue :
            
            if loStyle == wx.RB_GROUP:
                optBtn = wx.RadioButton(self,-1,label = optLable[name],
                                       size = size,pos = (100,0),style = wx.RB_GROUP)
                loStyle = None
                
            else:
                optBtn = wx.RadioButton(self,-1,label = optLable[name],
                                       size = size)
            
            setattr(self, name,optBtn)
            optBtnList.append(optBtn)

        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(self.chkbAll, 0, wx.EXPAND)
        #CheckBox's Layout
        for optBtn in optBtnList:
            box.Add(optBtn, 0, wx.EXPAND)

        self.SetSizer(box)
        
        self.Bind(wx.EVT_CHECKBOX, self.OnChkAll, self.chkbAll)
        
    def OnChkAll(self,event):
        """when "任意" have been selected"""
        if self.chkbAll.IsChecked():
            self.turnRadio(False)
        else:
            self.turnRadio(True)
    
    def turnRadio(self,value):
        if value:
            for optBtn in self.optBtnList:
                optBtn.Enable()
            
        else:
            for optBtn in self.optBtnList:
                optBtn.Enable(False)
    

class TestFrame(wx.Frame):
    def __init__(self,parent=None,id=-1,title= "TestFrame",size=(800,600)):
        wx.Frame.__init__(self,parent,id,title=title,size=size)
        self.mailPanel = wx.Panel(self)
        
        """Search Option Test"""
        self.testSearchOptionPnl()
        
    def testSearchOptionPnl(self):
        self.searchOption = SearchOptionPnl(self.mailPanel)
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.searchOption, 0, wx.EXPAND)
        self.mailPanel.SetSizer(box)
        
class TestApp(wx.App):
    def OnInit(self):
        #self.frame = bookSearchFrame(None, -1)
        self.frame = TestFrame(None, -1)
        self.SetTopWindow(self.frame)
        self.frame.Show()
        #result = self.frame.ShowModal()
        return True

if __name__ == "__main__":
    app = TestApp(0)
    app.MainLoop()